package com.xingyun.info_manager.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Classname WebMvcConfig
 * @Description MVC基本配置
 * @Date 2020/5/21 11:46
 * @Created by You
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public SecurityInterceptor getSecurityInterceptor() {
        return  new SecurityInterceptor();
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/").setViewName("forward:/login.html");
        //默认地址（可以是页面或后台请求接口）
        registry.addViewController("/").setViewName("forward:/info_manager/login.html");
        registry.addViewController("/info_manager").setViewName("forward:/info_manager/login.html");
        registry.addViewController("/info_manager/").setViewName("forward:/info_manager/login.html");
        //设置过滤优先级最高
//        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);

//        registry.addViewController("/").setViewName("login.html");
//        registry.addViewController("/index.html").setViewName("login.html");
    }

    @Override
    public  void addInterceptors(InterceptorRegistry registry){
        InterceptorRegistration addInterceptor = registry.addInterceptor(getSecurityInterceptor());
        //排除配置
        addInterceptor.excludePathPatterns("/**/admin/login","/css/**","/icheck/**","/layui/**","/image/**","/js/**","/javascript/**","/login.html");
        //拦截配置
        addInterceptor.addPathPatterns("/**");

    }
}
